package com.icode.web.controller.manager;

import com.icode.core.dto.manager.AssignmentDTO;
import com.icode.service.management.AssignmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sunk
 * Date: 15-11-15
 * Time: 下午10:00
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("assignment")
public class AssignmentController {
    @Autowired
    private AssignmentService assignmentService;

    @RequestMapping("init")
    private void init(@RequestBody AssignmentDTO assignmentDTO) {
        assignmentService.initAssignment(assignmentDTO);
    }

    @RequestMapping("list/{status}")
    private ModelAndView showAssignments(@PathVariable String status) {
        List<AssignmentDTO> assignmentDTOs = assignmentService.getAssignments(status);
        return new ModelAndView("", "assignmentDTOs", assignmentDTOs);
    }

    @RequestMapping("change/{assignmentGuid}/{myHouseGuid}")
    private void changeStatus(@PathVariable String assignmentGuid, @PathVariable String myHouseGuid) {
        assignmentService.changeStatus(assignmentGuid, myHouseGuid);
    }
}
